<?php
/** 留言板
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/3 0003
 * Time: 14:31
 */

//导入
include 'mysql.php';
$mysql = new mysql();
$id = $_SESSION['up_id'];
//留言内容查询
$sql = "select * from message where id = $id";
$data = $mysql->select_one($sql);
$text = $data['text'];
//修改
if (isset($_REQUEST['update2'])) {
    if (!empty($_POST)) {
        $text = $_POST['text'];
        //"UPDATE message SET text = '".$text."' WHERE  id = $id;";
        $data = array(
            'text' => $text
        );
        $table = 'message';
        $where = "id = $id";
        $ints = $mysql->update($data, $table, $where);
        if ($ints == true) {
            alert2('home.php', 0, "修改成功。");
        } else {
            alert2('update.php', 0, "修改失败。");
        }
    }
}

?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <script type="text/javascript" charset="utf-8" src="ed/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="ed/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="ed/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="ed/lang/zh-cn/zh-cn.js"></script>
    <title>留言板</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        input{
            width: 80px;
            height: 30px;
        }
        button{
            width: 100px;
            height: 30px;
        }
    </style>
</head>
<body>
<h1>发送留言</h1>
<form action="update.php" method="post">
    <script id="editor" name="text" type="text/plain"><?php echo $text;?></script>
    <input type="submit" value="修改" name="update2" onclick="return on_form()">
</form>
<div style="float: right;">
    <button onclick="btn2()">返回</button>
    <button onclick="btn1()">退出登录</button>
</div>
</body>
</html>
<script type="text/javascript">
    var ue = UE.getEditor('editor');
    function on_form() {
        /*let text = document.getElementById("editor").value;*/
        var text = UE.getEditor('editor').getContent();
        if(text == '' || text == null){
            alert("内容不能为空。");
            return false;
        }
    }
    function btn1() {
        var mymessage=confirm("确定要退出登录吗？");
        if(mymessage == true){
            window.location.href="login.php";
            return true;
        }else {
            window.location.href="update.php";
            return false;
        }
    }
    function btn2() {
        window.location.href="home.php";
    }
</script>